Subprogramm

Hello,
how can i transcription this problem.
I have some functions or subprogramms and i will define they in the first part of the programm and execute or access the codes in other parts of the programm.

void count1
{
    ...
}
 
void count2
{
    ...
}
 
...
...
...
 
count1
...
...
count2
 
(execute the "subprogramms" or functions)

SystemAdmin - Tue Oct 05 04:07:09 EDT 2010

Re: Subprogramm
Mathias Mamsch - Tue Oct 05 06:29:26 EDT 2010

void count1() { print "Count1" }
void count2() { print "Count2" }
 
print "Hello "; count1; print "\n"
print "Hello "; count2; print "\n"

 


OK, you are calling the subprograms/functions ... Seems to work. What is the problem? Are they in different files? Do you want to define the functions at runtime?

Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: Subprogramm
llandale - Wed Oct 06 15:36:01 EDT 2010

See Mathias' post.

Doh! I see it. Yes, functions that have no parameters must still have empty parenethesis after them (); and must include a brace pair {} after that. You wrote this:

void count1
{
    print "Count1\n"
}
print "After\n"
count1


which prints 'Count1 - After' when its run, since the interpreter doesn't know you are talking about a function. 'count1' is a variable of type 'void' and has nothing to do with the braced print statement which gets executed, then the 'After' print; refering to variable 'count1' at the bottom generated a dxl error reference to a null variable.

This is a syntactically correct function, with paranthesis:

 

void count1()
{
    print "Count1\n"
}
print "After\n"
count1


running that prints "After - Count1" since the function is defined but not executed until after the 'After' print.

 

 

 

  • Louie


PS. To reduce confusion, I ALWAYS call functions with the parenthesis, to make sure I can tell I'm calling a fuction. Last line would be count1().